/**  
* @Title: EmployeeAction.java
* @Package com.baili.controller.employeeManager
* @Description: TODO(用一句话描述该文件做什么)
* @author dingkunjie  
* @date 2016年1月7日 下午1:37:19
* @version V1.0  
*/ 
package com.baili.controller.employeeManager;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.ehcache.CacheManager;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.baili.dto.Employee;
import com.baili.service.employee.EmployeeService;
import com.baili.util.EhcacheUtil;

/**  
 * @Title: EmployeeAction.java
 * @Package com.baili.controller.employeeManager
 * @Description: demo
 * @author iceX  
 * @date 2016年1月7日 下午1:37:19
 * @version V1.0  
 */

@Controller
@Scope("prototype") 
@RequestMapping("/employee")
public class EmployeeAction {

	/**
	* @Fields logger : TODO(日志)
	*/
	Logger logger = Logger.getLogger(this.getClass().getName());
	
	@Autowired
	private EmployeeService employeeServiceImpl;
	
	@Autowired
	private CacheManager cacheManager;
	/**
	* @Title: setParamsToEhcache
	* @Description: 向ehcache中存入值
	* @param @return String
	* @return null  
	* @throws null
	* @author 丁坤杰
	 * @throws Exception 
	*/
	@RequestMapping("/setParamsToEhcache.htm")
	public String setParamsToEhcache() throws Exception {
		
		
		EhcacheUtil ehcache = new EhcacheUtil();
		ehcache.addToCache("ddd", "ddd");
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("key1", "aaa");
		map.put("key2", "bbb");
		
		ehcache.addToCache("map", map);
		
		return "success";
	}
	
	/**
	 * @Title: getParamsToEhcache
	 * @Description: 从ehcache中取出值
	 * @param @return String
	 * @return null  
	 * @throws null
	 * @author 丁坤杰
	 * @throws Exception 
	 */
	@RequestMapping("/getParamsToEhcache")
	public String getParamsToEhcache() throws Exception {
		
		
		EhcacheUtil ehcache = new EhcacheUtil();
		Object str = ehcache.getCacheElement("ddd");
		System.out.println(str);
		
		@SuppressWarnings("unchecked")
		Map<String,Object> map = (Map<String, Object>) ehcache.getCacheElement("map");
		System.out.println(map.get("key1"));
		System.out.println(map.get("key2"));
		
		return "success";
	}
	
	
	/**
	* @Title: showEmployee
	* @Description: employee展示
	* @param @return String
	* @return null  
	* @throws null
	* @author 丁坤杰
	*/
    @RequestMapping("/showEmployee1.htm")
    public String showEmployee1(){
    	
    	System.out.println("---------------------------------");
    	
        return "success";
    }
    
    /**
     * @Title: showEmployee
     * @Description: employee展示
     * @param @return String
     * @return null  
     * @throws null
     * @author 丁坤杰
     */
    @RequestMapping("/showEmployee.htm")
    public String showEmployee(){
    	
    	List<Map<String,Object>> employeeList = employeeServiceImpl.findAllEmpolyee();
    	
    	//创建ModelAndView对象
    	ModelAndView modelAndView = new ModelAndView();
    	//设置返回路径
    	modelAndView.setViewName("showEmployee");
    	modelAndView.addObject("employeeList", employeeList);
    	
    	return "employee/showEmployee";
    }
    
    /**
     * @Title: skipAddEmployee
     * @Description: 跳转到增加employee页面
     * @param @return String
     * @return null  
     * @throws null
     * @author 丁坤杰
     */
    @RequestMapping("/skipAddEmployee.htm")
    public String skipAddEmployee(){
    	
    	return "employee/showEmployee";
    }
	
    
	/**
	* @Title: addEmployee
	* @Description: 增加employee
	* @param @return ModelAndView
	* @return null  
	* @throws null
	* @author 丁坤杰
	*/
    @RequestMapping("/addEmployee.htm")
    public ModelAndView addEmployee(Employee employee){
    	
    	int result = employeeServiceImpl.addEmployee(employee);
    	
    	//创建ModelAndView对象
    	ModelAndView modelAndView = new ModelAndView();
    	//设置返回路径
    	modelAndView.setViewName("showEmployee");
    	
    	return new ModelAndView("showEmployee");
    }
    
	
}
